package com.lcxw.hxzbapi.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.lcxw.hxzbapi.dao.mapper.SvLikeMapper;
import com.lcxw.hxzbapi.entity.pojo.SvLike;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class SvLikeService {

    @Resource
    SvLikeMapper svLikeMapper;

    //增加一个短视频点赞
    public int insert(SvLike svLike) {
        return svLikeMapper.insert(svLike);
    }

    //删除一个短视频点赞
    public int delete(int likeId) {
        UpdateWrapper<SvLike> wrapper = new UpdateWrapper<>();
        wrapper.eq("likeId", likeId);
        return svLikeMapper.delete(wrapper);
    }

    //获取短视频的点赞数量
    public int getLikes(Integer svId) {
        QueryWrapper<SvLike> wrapper = new QueryWrapper<>();
        wrapper.eq("svId", svId);
        return svLikeMapper.selectCount(wrapper);
    }

    public SvLike getSvlike(Integer svId, long userId) {
        QueryWrapper<SvLike> wrapper = new QueryWrapper<>();
        wrapper.eq("svId", svId);
        wrapper.eq("userId", userId);
        return svLikeMapper.selectOne(wrapper);
    }

}
